package logic

import (
	"context"
	"fmt"
	"home-manager/homerpc/model"

	"home-manager/homerpc/homerpc"
	"home-manager/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeShowLogic {
	return &HomeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HomeShowLogic) HomeShow(in *homerpc.HomeShowRequest) (*homerpc.HomeShowResponse, error) {
	// todo: add your logic here and delete this line

	var home model.Home
	if in.Id == 0 {
		return nil, fmt.Errorf("无数据")
	}
	model.DB.Debug().Where("id=?", in.Id).First(&home)
	return &homerpc.HomeShowResponse{
		Id:      int64(home.ID),
		Img:     home.Img,
		Title:   home.Title,
		Status:  home.Status,
		Address: home.Address,
		Price:   float32(home.Price),
	}, nil
}
